package com.eryos.android.cigarettecounter.tool;

import java.util.Calendar;

import android.content.Context;

import com.eryos.android.cigarettecounter.R;

/**
 * Project :  CigaretteCounter
 * Author :   Olivier Combe 
 * URL :      http://eryos.fr/CigaretteCounter/
 *
 * Copyright (C) 2011 - Olivier Combe 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

public class Tools {

	/**
	 * Return the last day of the month in param
	 * @param month number ( from 1 to 12 )
	 * @return
	 */
	public static int getLastDayOfMonth( int month ){

		Calendar c = Calendar.getInstance(); 
		c.set(Calendar.MONTH, month+1); 
		c.set(Calendar.DAY_OF_MONTH, 1); 
		c.add(Calendar.DAY_OF_MONTH, -1);

		return c.get(Calendar.DAY_OF_MONTH);
	}
	
	
    
    /**
     * Last day of the month with data ( date format : 23/01/2011 )
     * @param ctx
     * @param _date
     * @return
     */
	public static String getMonthLabel( Context ctx, String _date){
    	try {
			String month = _date.substring(3,5);
			Integer i = new Integer(month);

			switch(i){
				case 1:
					return ctx.getResources().getString(R.string.month_january_full);
				case 2:
					return ctx.getResources().getString(R.string.month_february_full);
				case 3:
					return ctx.getResources().getString(R.string.month_march_full);
				case 4:
					return ctx.getResources().getString(R.string.month_april_full);
				case 5:
					return ctx.getResources().getString(R.string.month_may_full);
				case 6:
					return ctx.getResources().getString(R.string.month_june_full);
				case 7:
					return ctx.getResources().getString(R.string.month_july_full);
				case 8:
					return ctx.getResources().getString(R.string.month_august_full);
				case 9:
					return ctx.getResources().getString(R.string.month_september_full);
				case 10:
					return ctx.getResources().getString(R.string.month_october_full);
				case 11:
					return ctx.getResources().getString(R.string.month_november_full);
				case 12:
					return ctx.getResources().getString(R.string.month_december_full);
			}
		} catch (Exception e) {
			System.out.println("getMonthLabel : "+_date);
			e.printStackTrace();
			return "NA";
		}
	
	return "NA";
    }
    
	/**
	 * 
	 * @param ctx
	 * @param month
	 * @return
	 */
    public static String getMonthFirstLetter(Context ctx, int month){
    	switch(month){
	    	case 1:
	    		return ctx.getResources().getString(R.string.month_january);
	    	case 2:
	    		return ctx.getResources().getString(R.string.month_february);
	    	case 3:
	    		return ctx.getResources().getString(R.string.month_march);
	    	case 4:
	    		return ctx.getResources().getString(R.string.month_april);
	    	case 5:
	    		return ctx.getResources().getString(R.string.month_may);
	    	case 6:
	    		return ctx.getResources().getString(R.string.month_june);
	    	case 7:
	    		return ctx.getResources().getString(R.string.month_july);
	    	case 8:
	    		return ctx.getResources().getString(R.string.month_august);
	    	case 9:
	    		return ctx.getResources().getString(R.string.month_september);
	    	case 10:
	    		return ctx.getResources().getString(R.string.month_october);
	    	case 11:
	    		return ctx.getResources().getString(R.string.month_november);
	    	case 12:
	    		return ctx.getResources().getString(R.string.month_december);
    	}
    	
    	return "NA";
    }
    
    /**
     * 
     * @param ctx
     * @param day
     * @return
     */
    public static String getDayFirstLetter(Context ctx, int day){
    	switch(day){
    	case 0:
    		return ctx.getResources().getString(R.string.week_sunday);
    	case 1:
    		return ctx.getResources().getString(R.string.week_monday);
    	case 2:
    		return ctx.getResources().getString(R.string.week_tuesday);
    	case 3:
    		return ctx.getResources().getString(R.string.week_wednesday);
    	case 4:
    		return ctx.getResources().getString(R.string.week_thursday);
    	case 5:
    		return ctx.getResources().getString(R.string.week_friday);
    	case 6:
    		return ctx.getResources().getString(R.string.week_saturday);
    	}
    	
    	return "NA";
    }
	
}
